package at.fhhgb.mc.android.mfb_hgb.activity;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import at.fhhgb.mc.android.mfb_hgb.R;

public class NavigationDrawerMenuAdapter extends ArrayAdapter<NavigationDrawerMenuItem> {
	// internal list of the relevant data
	List<NavigationDrawerMenuItem> mList;
	final Context c;

	public NavigationDrawerMenuAdapter(Context _context, int _textViewResourceId, List<NavigationDrawerMenuItem> _objects) {
		super(_context, _textViewResourceId, _objects);
		c = _context;
		mList = _objects;
	}

	@Override
	public View getView(int _position, View _convertView, ViewGroup _parent) {
		if (_convertView == null) {
			Context c = getContext();
			LayoutInflater inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			_convertView = inflater.inflate(R.layout.fragment_navigation_drawer_item, null);
		}

		final NavigationDrawerMenuItem element = mList.get(_position);
		if (element != null) {
			TextView v = null;
			v = (TextView) _convertView.findViewById(R.id.nav_item_title);
			v.setText(element.getName());

			ImageView i = null;
			i = (ImageView) _convertView.findViewById(R.id.nav_item_icon);
			i.setImageResource(element.getIcon());

		} // if element
		return _convertView;
	}
}
